<script setup lang="ts">
defineOptions({ 
    name: 'FollowDoctor' 
})

// import { onMounted, onUnmounted, ref } from 'vue';
import type { DoctorList } from '@/types/consult';
import DoctorCard from './DoctorCard.vue';

// 屏幕自适应 vueuse 的方法
// 导入vueuse的包
import { useWindowSize } from '@vueuse/core'
import { onMounted, ref } from 'vue';
import { getDoctorListAPI } from '@/apis/consult';
const { width: dWidth } = useWindowSize()

// 屏幕自适应 原生js的方法
// const dWidth = ref(0)
// // 当页面加载或者设备的尺寸发生变化时都应该获取设备的宽度
// const setWidth = () => (dWidth.value = window.innerWidth)
// onMounted(() => {
//     setWidth()
        // 添加事件监听
//     window.addEventListener('resize', setWidth)
// })

// onUnmounted(() => {
        // 删除事件监听
//     window.removeEventListener('resize', setWidth)
// })

const list = ref<DoctorList>([])

const getDoctorList = async () => {
    const res = await getDoctorListAPI({
        current: 1,
        pageSize: 5
    })
    // console.log(res)
    list.value = res.data.rows
}

onMounted(() => {
    getDoctorList()
})


</script>

<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
    <van-swipe :loop="false" :show-indicators="false" :width="(150 / 375) *dWidth">
        <van-swipe-item v-for="item in list" :key="item.id">
            <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
    </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
